package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听器，接收pre_send_sms_topic队列中的短信对象
 * @author lenovo
 * @version V1.0
 * @Date 2021/11/22 20:44
 */
@Component
@Slf4j
public class StandardSmsListener {

    @Autowired
    private FilterChainService filterChainService;

    /**
     * 接收mq中的消息对象，让消息对象走策略模块
     */

    @RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
    public void messageHandler(Message message, Channel channel,StandardSubmit standardSubmit) throws IOException {
        log.info("【策略模块 - 监听器】接收队列中的短信对象，standardSubmit={}",standardSubmit);

        filterChainService.executerFilter(standardSubmit);

        //手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }


}
